using Microsoft.VisualStudio.TestTools.UnitTesting;

using System.Reflection;
using System.Collections.Generic;
using System.IO;

using Weazel.Gezel.Model;
using Weazel.Gezel.Model.Errors;
using Weazel.Gezel.Parser;

namespace Weazel.Gezel.Parser.Test
{
  [TestClass]
  public class TestParseModel
  {
    private string getResourceString(string resourceName)
    {
      Assembly assembly = Assembly.GetExecutingAssembly();
      StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream(resourceName));

      return textStreamReader.ReadToEnd();
    }

    [TestMethod]
    public void TestParseAdderFdl()
    {
      string model = getResourceString("Weazel.Gezel.Parser.Test.Models.adder.fdl");
      List<ParseError> errors = new List<ParseError>();
      Weazel.Gezel.Model.Model m = ParseModel.Parse(ref errors, model);
      Assert.AreEqual(errors.Count, 0);
    }

    [TestMethod]
    public void TestParseGcdFdl()
    {
      string model = getResourceString("Weazel.Gezel.Parser.Test.Models.gcd.fdl");
      List<ParseError> errors = new List<ParseError>();
      Weazel.Gezel.Model.Model m = ParseModel.Parse(ref errors, model);
      Assert.AreEqual(errors.Count, 0);
    }

    [TestMethod]
    public void TestParseScriptedFdl()
    {
      string model = getResourceString("Weazel.Gezel.Parser.Test.Models.scripted.fdl");
      List<ParseError> errors = new List<ParseError>();
      Weazel.Gezel.Model.Model m = ParseModel.Parse(ref errors, model);
      Assert.AreEqual(errors.Count, 0);
    }

    [TestMethod]
    public void TestParseAesFdl()
    {
      string model = getResourceString("Weazel.Gezel.Parser.Test.Models.aes.fdl");
      List<ParseError> errors = new List<ParseError>();
      Weazel.Gezel.Model.Model m = ParseModel.Parse(ref errors, model);
      Assert.AreEqual(errors.Count, 0);
    }

    [TestMethod]
    public void TestParseBresenFdl()
    {
      string model = getResourceString("Weazel.Gezel.Parser.Test.Models.bresen.fdl");
      List<ParseError> errors = new List<ParseError>();
      Weazel.Gezel.Model.Model m = ParseModel.Parse(ref errors, model);
      Assert.AreEqual(errors.Count, 0);
    }

    [TestMethod]
    public void TestParseEuclidFdl()
    {
      string model = getResourceString("Weazel.Gezel.Parser.Test.Models.euclid.fdl");
      List<ParseError> errors = new List<ParseError>();
      Weazel.Gezel.Model.Model m = ParseModel.Parse(ref errors, model);
      Assert.AreEqual(errors.Count, 0);
    }

    [TestMethod]
    public void TestParseRamBlockFdl()
    {
      string model = getResourceString("Weazel.Gezel.Parser.Test.Models.ramblock.fdl");
      List<ParseError> errors = new List<ParseError>();
      Weazel.Gezel.Model.Model m = ParseModel.Parse(ref errors, model);
      Assert.AreEqual(errors.Count, 0);
    }
  }
}